from 算法.high.queue.queue import list_toqueue, print_que, RandomListNode


class Solution(object):
    
    def copyRandomList(self, head:RandomListNode):
        """
        :type head: RandomListNode
        :rtype: RandomListNode
        """
        if head == None:
            return head
        p1 = head
        while p1:
            p2 = RandomListNode(p1.label)
            p2.next = p1.next
            p2.random = p1.random
            p1.next = p2
            p1 = p2.next
        a_head = head.next
        p1 = a_head
        while p1.next:
            if p1.random:
                p1.random = p1.random.next
            else:
                p1.random = None
            p1.next = p1.next.next
            p1 = p1.next

        return a_head
        
        
        